package Month10.day1011;

public class Test2 {
    public static int method1(int[] a,int index){//返回数组下标元素
        if(a == null){
            throw new NullPointerException("这里发生了空指针异常");
        }
        System.out.println("排除空指针异常");

        if(index < 0 || index > a.length - 1){
            throw new ArrayIndexOutOfBoundsException("这里发生了数组越界异常");
        }
        System.out.println("排除数组越界异常");
        return a[index];
    }

    public static void main(String[] args) {
        int[] a = {1,2,3,4,5,6,7};
        //System.out.println(method1(null,1));
        //System.out.println(method1(a,10));
        System.out.println( method1(a,2));
    }
}
